package com.cn.music;

import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.cn.music.databinding.ActivityMainBinding;
import com.cn.music.view.UserDetailViewModel;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;
    private UserDetailViewModel viewModel;
    private String uid;
    private static final String TAG = "主界面";
    private ActionBarDrawerToggle toggle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        viewModel = new ViewModelProvider(this).get(UserDetailViewModel.class);
        uid = getIntent().getStringExtra("uid");
        viewModel.loadUserDetailModel(uid).observe(this, userDetailModels -> {
            Log.e(TAG,"userDetailModels"+userDetailModels);
        });
        initToolBar();
    }

    private void initToolBar() {
        setSupportActionBar(binding.toolBar);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toggle = new ActionBarDrawerToggle(this,binding.drawerLayout,binding.toolBar,R.string.open_drawer,R.string.close_drawer){
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
            }
        };
        toggle.syncState();

    }

}